package com.mtf.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author matengfei
 * @Date 2024/7/4 10:14
 * @PackageName:com.mtf.config
 *
 *
 *
 *
 * @ClassName: JedisPoolManager
 * @Description: Jedis实例连接池
 * @Version 1.0
 */
public class JedisPoolManager {

    //ps：不能注入静态字段
    //@Value("${spring.redis.host}")
    //private static String localhost;
    private final static String localhost = "127.0.0.1";

    private static final JedisPool pool;

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(128);
        config.setMaxIdle(128);
        config.setMinIdle(16);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        config.setTestWhileIdle(true);
        pool = new JedisPool(config, localhost, 6379);
    }

    public static JedisPool getPool() {
        return pool;
    }
}
